IsFileWriteable: probe via permission bits, not append-open#20
Merged
Conversation
The previous implementation tested writability by opening the file with ios_base::app|out, which: 1. As a side effect, created empty files when probing non-existent paths (relevant on platforms where ScanFiles might pass through transient candidate paths). 2. On iOS keyboard extensions, where the data bundle is read-only and sandboxed, generated a 'file-write-data' sandbox deny for every bundled file scanned (colour XMLs, alphabet XMLs, etc.). Each deny produced a kernel log line and forced the kernel to set up + tear down a denied file descriptor. Replace the open-with-append with std::filesystem::status(), checking the permission bits for any write bit (owner/group/others). This is: - Side-effect free: never creates files. - Faster: one stat() per file instead of open()+close(). - Sandbox-clean: no write attempts against read-only paths. Semantically equivalent for all callers (ScanFiles only invokes IsFileWriteable on paths that already exist as regular files, so the 'non-existent file' case doesn't apply in practice). Signed-off-by: will wade <willwade@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
IsFileWriteable()tested writability by opening the file withios_base::app | out. Two problems with that:.appexcontainer. EveryScanFiles()call probed each scanned file with an append-open, producing aSandbox: deny file-write-datalog line per file from the kernel. Several dozen denies perRealize()call.What this changes
Replaces the open-and-check with
std::filesystem::status()and a permission-bit check for any write bit (owner/group/others).stat()instead ofopen()+close().Compatibility
Semantically equivalent for all current callers.
ScanFiles()only invokesIsFileWriteable()on entries thatrecursive_directory_iteratoralready returned asis_regular_file(), so the non-existent-file edge case doesn't arise in practice. The new code handles it anyway (returnsfalseonstatus()error).No public API change. No header change. Drop-in for all frontends (Apple, Windows, GTK, WASM).
Verification
Built and verified on iOS via the Dasher Apple keyboard extension. Sandbox denies during
Realize()are gone; no regressions in DasherApp, DasherMac, or DasherVision.